<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="col-md-12">
	<div class="panel-search">
	  <form class="form-inline" action="/processDefinition/list" id="processDefinitionForm">
	    <div class="fileinput fileinput-new" data-provides="fileinput">
			<label class="control-label">发布新流程:</label>
			
				<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 150px; height: 30px;">
				</div>
				
				<span class="btn default btn-file">
					<span class="fileinput-new">浏览流程定义zip压缩文件</span>
					<span class="fileinput-exists">编辑</span>
					<input type="file" name="zipFile">
				</span>
				<a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput">删除</a>
		</div>
	  </form>
	  <div class="btn-div">
			<div class="div-left">
				<button type="button" class="btn btn-primary" onclick="upload();">
					<i class="glyphicon glyphicon-open"></i> <spring:message code="btn.upload"></spring:message>
				</button>
			</div>
		</div>
	</div>
	<div class="panel-content"></div>
</div>
<script type="text/javascript">
	$(function(){
		search();
	});
	
	function upload() {
		
		var fileVal = $("input[name='zipFile']").val();
		if(fileVal == "") {
			layer.msg("请选择一个上传的文件!", {shift: 6});
			return;
		}
		
		var formData = new FormData($('#processDefinitionForm')[0]);
		$.ajax({
			type: 'post',
			url: '<c:url value="/processDefinition/deploy"></c:url>',
			data: formData,
			async: false,  
		    cache: false,  
		    contentType: false,  
		    processData: false, 
			success: function(data){
				if(data.code == 0) {
					layer.msg(data.message, {shift: 1});
					setTimeout(function(){
						search();
					}, 1200);
				}else {
					layer.msg(data.message, {shift: 6});
				}
			}
		})
	}
</script>